<template>
  <div>
    <div v-if="power===3">
      <h1>Workstate</h1>
      <!--搜索框-->
      <el-form :inline="true" ref="form" :model="queryLike" label-width="80px">
        <el-form-item label="任务id">
          <el-input v-model="queryLike.wid" placeholder="输入要查找的任务id"></el-input>
        </el-form-item>
        <el-form-item label="标签">
          <el-input v-model="queryLike.title" placeholder="输入要查找的标签"></el-input>
        </el-form-item>
        <el-form-item label="转发方id">
          <el-input v-model="queryLike.belong" placeholder="输入要查找的转发方id"></el-input>
        </el-form-item>
        <br>
        <el-form-item label="接收方id">
          <el-input v-model="queryLike.to" placeholder="输入要查找的接收方id"></el-input>
        </el-form-item>
        <el-form-item label="状态码">
          <el-radio-group v-model="queryLike.state">
            <el-radio :label="1">正常工作中</el-radio>
            <el-radio :label="0">封禁</el-radio>
            <el-radio :label="3">完成</el-radio>
            <el-radio :label="2">提交中</el-radio>
            <el-radio :label="4">转发中</el-radio>
            <el-radio :label="''">所有</el-radio>
          </el-radio-group>
        </el-form-item>
        <br>
        <el-form-item label="创建时间">
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择开始日期" v-model="queryLike.startTime1"
                            style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align:center">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择开始时间" v-model="queryLike.startTime2" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择结束日期" v-model="queryLike.endTime1"
                            style="width: 100%;"></el-date-picker>
          </el-col>
          <el-col class="line" :span="2" style="text-align:center">-</el-col>
          <el-col :span="11">
            <el-time-picker placeholder="选择结束时间" v-model="queryLike.endTime2" style="width: 100%;"></el-time-picker>
          </el-col>
        </el-form-item>
        <br>
        <el-form-item label="排序类型">
          <el-radio-group v-model="queryLike.sortType">
            <el-radio :label="1">降序</el-radio>
            <el-radio :label="0">升序</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="排序依据">
          <el-radio-group v-model="queryLike.sortBy">
            <el-radio :label="10">创建时间</el-radio>
            <el-radio :label="2">价格</el-radio>
            <el-radio :label="0">浏览量</el-radio>
            <el-radio :label="1">月销量</el-radio>
            <el-radio :label="3">修改时间</el-radio>
          </el-radio-group>
        </el-form-item>
        <br>
        <el-form-item label="页数">
          <el-input v-model="queryLike.page" width="20" placeholder="输入当前页"></el-input>
        </el-form-item>
        <el-form-item label="页内条数">
          <el-input v-model="queryLike.pageSize" width="20" placeholder="输入单页总条数"></el-input>
        </el-form-item>
        <el-form-item>
          <!--查询按钮-->
          <el-button type="primary" @click="search(queryLike)" icon="el-icon-search" value="查询"></el-button>
          <!--添加按钮-->
          <el-button style="float:right" type="success" icon="el-icon-circle-plus-outline" @click="insert()"
                     value="添加"></el-button>
        </el-form-item>
      </el-form>
      <!--添加填出的对话框(和修改是同一个)-->
      <el-dialog title="商家信息" :visible.sync="dialogFormVisible">
        <el-form :model="pojo">
          <el-form-item label="任务id" :label-width="formLabelWidth">
            <el-input v-model="pojo.wid" autocomplete="on"></el-input>
          </el-form-item>
          <el-form-item label="标签" :label-width="formLabelWidth">
            <el-input v-model="pojo.title" autocomplete="on"></el-input>
          </el-form-item>
          <el-form-item label="转发者" :label-width="formLabelWidth">
            <el-input v-if="pojo.belong!==null&&pojo.belong!==undefined" v-model="pojo.belong.id" autocomplete="on"></el-input>
          </el-form-item>
          <el-form-item label="接收者" :label-width="formLabelWidth">
            <el-input v-if="pojo.to!==null&&pojo.to!==undefined" v-model="pojo.to.id" autocomplete="on"></el-input>
          </el-form-item>
          <el-form-item label="状态码" :label-width="formLabelWidth">
            <el-input v-model="pojo.state" autocomplete="on"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="save(pojo)">确 定</el-button>
        </div>
      </el-dialog>
      <!--列表-->
      <el-table :data="user" style="width: 100%" max-height="600">
        <el-table-column fixed property="wsid" label="主键"></el-table-column>
        <el-table-column property="wid" label="任务id"></el-table-column>
        <el-table-column property="title" label="标签"></el-table-column>
        <el-table-column property="belong.id" label="转发来自id"></el-table-column>
        <el-table-column property="belong.name" label="转发来自账号"></el-table-column>
        <el-table-column property="to.id" label="转发给id"></el-table-column>
        <el-table-column property="to.name" label="转发给账号"></el-table-column>
        <el-table-column property="state" label="状态码"></el-table-column>
        <el-table-column property="creattime" label="创建时间" width="150"></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="200">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-setting" value="修改" @click="change(scope.row)" circle></el-button>
            <el-button v-if="scope.row.state===1" type="info" icon="el-icon-video-pause" value="封禁"
                       @click="dele(scope.row)" circle></el-button>
            <el-button v-if="scope.row.state!==1" type="info" icon="el-icon-video-play" value="启用"
                       @click="enable(scope.row)" circle></el-button>
            <el-button v-if="power===3" type="danger" icon="el-icon-delete" value="删除" @click="phydele(scope.row)"
                       circle></el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div v-if="power!==3">
      <h1>权限不够,不予开放</h1>
    </div>
  </div>
</template>

<script>

export default {
  name: "Workstate",
  computed: {
    baseURL() {
      return this.$store.state.baseURL;
    }
  },
  props: {},
  data() {
    return {
      /***
       * @修改和添加数据类型
       * */
      pojo: this.$store.state.Pojo.WorkstateVo,
      /**
       * @弹出的对话框,用于修改和添加数据
       * */
      dialogFormVisible: false,
      /**
       * @对话框内条目的统一长度
       * */
      formLabelWidth: '120px',
      /**
       * @表单数据
       * */
      user: this.$store.state.List.WorkstateVo,
      /**
       * @权限,页面显示不同权限的操作
       * */
      power: this.$store.state.operator.power,
      /**
       * @查询条件
       * */
      queryLike: {
        OperatorId: "",
        endTime1: "2099-01-01 00:00:00.000+0000",
        endTime2: "2099-01-01 00:00:00.000+0000",
        wid: "",
        title: "",
        belong:"",
        to:"",
        state:"",
        page: 1,
        pageSize: 10,
        sortBy: 10,
        sortType: 1,
        startTime1: "2000-01-01 00:00:00.000+0000",
        startTime2: "2000-01-01 00:00:00.000+0000",
      },
      /**
       * @后端controller名字
       * */
      controller: 'Workstate',
    };
  },
  /**
   * @加载数据
   */
  created() {
    this.LoadMsg();
  },
  /**
   * @static方法
   * */
  mounted() {
    (() => {
      /*console.log(this.$store.state.operator)
      this.power=this.$store.state.operator["power"];
      console.log(this.power);
      console.log(typeof (this.power))*/
    })();
  },
  methods: {
    /**
     * @失去焦点事件
     * */
    onEditorBlur(){},
    /**
     * @获得焦点事件
     * */
    onEditorFocus(){},
    /**
     * @内容改变事件
     * */
    onEditorChange(){},
    /**
     * @嵌入内容
     * */
    Content(val) {
      this.centerDialogVisible = true;
      this.content = val;
    },
    /**
     * @添加
     * */
    insert() {
      this.pojo.wsid='';
      this.pojo.wid="";
      this.pojo.title="";
      if(this.pojo.belong===null||this.pojo.belong===undefined){
        this.pojo.belong={
          id:''
        };
      }else {
        this.pojo.belong.id = "";
      }
      if(this.pojo.to===null||this.pojo.to===undefined){
        this.pojo.to={
          id:''
        };
      }else {
        this.pojo.to.id = "";
      }
      this.pojo.state=1;
      this.dialogFormVisible = true;
    },
    /**
     * @修改
     * */
    change(val) {
      //console.log(val)
      this.pojo = this.$helper.clone(val);
      if(this.pojo.belong===null||this.pojo.belong===undefined){
        this.pojo.belong={
          id:''
        };
      }else {
        this.pojo.belong.id = "";
      }
      if(this.pojo.to===null||this.pojo.to===undefined){
        this.pojo.to={
          id:''
        };
      }else {
        this.pojo.to.id = "";
      }
      this.dialogFormVisible = true;
    },
    /**
     * @保存
     */
    save(val) {
      //console.log(val)
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id,
        {
          wsid: val.wsid,
          wid: val.wid,
          title: val.title,
          belong: val.belong,
          to: val.to,
          state: val.state
        })
        .then(res => {
          //console.log(res.data)
          _this.search(_this.queryLike);
        })
      this.dialogFormVisible = false;
    },
    /**
     * @启用
     */
    enable(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id ,{
        wsid:val.wsid,
        state:1
      })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @物理删除
     */
    phydele(val) {
      let _this = this;
      this.axios.delete(this.$store.state.baseURL + 'client/' + this.controller + '/delete?' + 'OperatorId=' + this.$store.state.operator.id + '&id=' + val.wsid)
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @封禁
     */
    dele(val) {
      let _this = this;
      this.axios.post(this.$store.state.baseURL + 'client/' + this.controller + '/save?' + 'OperatorId=' + this.$store.state.operator.id,
        {
          wsid:val.wsid,
          state:0
        })
        .then(res => {
          _this.search(_this.queryLike);
        })
    },
    /**
     * @查询
     * */
    search(val) {
      let _this = this;
      //console.log(val);
      this.axios.get(this.$store.state.baseURL + 'client/' + this.controller + '/queryLike?'
        + 'OperatorId=' + this.$store.state.operator.id
        + '&wid=' + val.wid
        + '&title=' + val.title
        + '&belong=' + val.belong
        + '&to=' + val.to
        + '&state=' + val.state
        + '&sortBy=' + val.sortBy
        + '&sortType=' + val.sortType
        + '&page=' + val.page
        + '&pageSize=' + val.pageSize
        + '&startTime=' + this.$helper.renderTime(val.startTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.startTime2).split(' ')[1]
        + '&endTime=' + this.$helper.renderTime(val.endTime1).split(' ')[0] + ' ' + this.$helper.renderTime(val.endTime2).split(' ')[1]
      )
        .then(res => {
          _this.$store.state.List.WorkstateVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(_this.user);
        })
    }
    ,
    /**
     *
     * @导入具体列表的数据
     */
    LoadMsg() {
      let _this = this;
      this.axios.get(this.$store.state.baseURL + 'client/' + this.controller + '/queryLike?' + 'OperatorId=' + this.$store.state.operator.id )
        .then(res => {
          _this.$store.state.List.WorkstateVo = res.data;
          _this.LoadInfo(res.data);
          //console.log(res.data);
        })
    }
    ,
    /**
     *
     * @更新当前页面的数据(data<->this.$store.state)
     */
    LoadInfo(val) {
      this.user = val;
    }
    ,
  },
}
</script>

<style scoped>
.line-limit-length {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap; /*文本不换行，这样超出一行的部分被截取，显示...*/
}
.product-buyer-name {
  max-width: 180px;
  max-height: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.el-select .el-input {
  width: 130px;
}

.input-with-select .el-input-group__prepend {
  background-color: #fff;
}

.el-tag + .el-tag {
  margin-left: 10px;
}

.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}

.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
